package com.inspur.dgov.bsp.application.wrapper;

import cn.hutool.core.bean.BeanUtil;
import com.inspur.dgov.bsp.application.entity.PubRole;
import com.inspur.dgov.bsp.application.service.PubRoleService;
import com.inspur.dgov.bsp.application.vo.RoleVO;
import com.inspur.dgov.common.boot.mapper.BaseEntityWrapper;
import com.inspur.dgov.common.tool.node.TreeNodeUtil;
import com.inspur.dgov.common.tool.utils.SpringContextHolder;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 角色包装类
 *
 * @Author chiyupei
 * @Date 20/3/20 下午11:19
 * @Version 1.0
 * @Description 角色包装类,返回视图层所需的字段
 */
public class PubRoleWrapper extends BaseEntityWrapper<PubRole, RoleVO> {

    private static PubRoleService pubRoleService;

    static {
        pubRoleService = SpringContextHolder.getBean(PubRoleService.class);
    }

    public static PubRoleWrapper build() {
        return new PubRoleWrapper();
    }

    @Override
    public RoleVO entityVO(PubRole role) {
        RoleVO roleVO = new RoleVO();
        BeanUtil.copyProperties(role, roleVO);
//        if (null == resource.getParentId()) {
//            resourceVO.setParentName("");
//        } else {
//            PubResource parent = this.pubResourceService.getById(resource.getParentId());
//            resourceVO.setParentName(parent.getName());
//        }
        return roleVO;
    }

    public List<RoleVO> listVO(List<PubRole> list) {
        List<RoleVO> collect = list.stream().map(this::entityVO).collect(Collectors.toList());
        return TreeNodeUtil.merge(collect);
    }
}
